package simplechat.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: netty-study
 * @description: 消息工具类
 * @author: 胡海龙
 * @create: 2021-04-10 23:31:10
 **/
public class MessageUtil {

    public static Map<String,String> getInfoByMessage(String message){
        Map<String,String> result = new HashMap<>();
        String[] temp = message.split("&");
        String parseStr = temp[temp.length-1];
//        System.out.println(parseStr);
        String sendMessageName = parseStr.split("from")[1].split("to")[0].trim();
        StringBuilder tempMessage = new StringBuilder();
        for(int i=0; i<temp.length-1; i++){
            tempMessage.append(temp[i]);
        }
        String sendMessage = tempMessage.toString();
        result.put("sendName",sendMessageName);
        result.put("sendMessage",sendMessage);
        return result;
    }

    public static String getFromName(String message){
        String[] temp = message.split("&");
        return temp[temp.length-1].split("from")[1].split("to")[0].trim();
    }

    public static String getToName(String message){
        String[] temp = message.split("&");
        return temp[temp.length-1].split("to")[1].trim();
    }
}
